//
// Created by Tony on 2023/8/20.
//

#ifndef COMMON_UTILS_H
#define COMMON_UTILS_H

#define MIN2(a, b) (a < b ? a : b)
#define MAX2(a, b) (a > b ? a : b)

#define MAX3(a, b, c) (MAX2(MAX2(a, b), c))
#define MIN3(a, b, c) (MIN2(MIN2(a, b), c))

#define COMPARE(a, b) (a < b ? -1 : (a > b ? 1 : 0))

#define CHECK_FALSE_RETURN(value, ret)                                                             \
    do {                                                                                           \
        if (!(value)) {                                                                            \
            return ret;                                                                            \
        }                                                                                          \
    } while (0)

#define CHECK_NULL_RETURN(ptr, ret)                                                                \
    do {                                                                                           \
        if (!(ptr)) {                                                                              \
            return ret;                                                                            \
        }                                                                                          \
    } while (0)

#define CHECK_ZERO_RETURN(value, ret)                                                              \
    do {                                                                                           \
        if (value == 0) {                                                                          \
            return ret;                                                                            \
        }                                                                                          \
    } while (0)

#define CHECK_NEGATIVE_RETURN(value, ret)                                                          \
    do {                                                                                           \
        if (value < 0) {                                                                           \
            return ret;                                                                            \
        }                                                                                          \
    } while (0)

#endif // COMMON_UTILS_H
